package com.hmall.cart.listener;

import com.hmall.cart.service.ICartService;
import com.hmall.common.domain.ItemUser;
import com.hmall.common.utils.UserContext;
import lombok.RequiredArgsConstructor;
import org.apache.catalina.User;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
@RequiredArgsConstructor
public class RabbitMqListener {

    private final ICartService cartService;

    @RabbitListener(bindings =
    @QueueBinding(
            value = @Queue(name = "cart.clear.queue",durable = "true"),
            exchange =@Exchange(name = "trade.topic",type = ExchangeTypes.TOPIC),
            key = "order.create"
    ))
    public void listenMessage(Collection<Long> itemIds){
        cartService.removeByItemIds(itemIds);
    }
}
